<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<?php 
	$USER = getAccountUserObject(true);
?>

<form action="<?php echo site_url('agent/my_account/submit_personal_info');?>" name="submit_personal_info" id="submit_personal_info" method="post" enctype="multipart/form-data" >
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left">
			<span><?php echo language_translate('agent_personal_info_name');?></span>
		</div>
		<div class="dashboard-info-right">
			<div class="input-box">
				<input type="text" value="<?php echo $USER->getName();?>" name="personal_info_name" class="text-box3" maxlength="45" />
			</div>
			<div class="clear"></div>
		</div>
		<div class="clear"></div>
	</div>
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left">
			<span><?php echo language_translate('agent_personal_info_phone');?></span>
		</div>
		<div class="dashboard-info-right">
			<div class="input-box">
				<input type="text" value="<?php echo $USER->getPhone();?>" name="personal_info_phone" class="text-box3" maxlength="45" />
			</div>
			<div class="clear"></div>
		</div>
		<div class="clear"></div>
	</div>
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left">
			<span><?php echo language_translate('agent_personal_info_address');?></span>
		</div>
		<div class="dashboard-info-right">
			<div class="input-box">
				<input type="text" value="<?php echo $USER->getAddress();?>" name="personal_info_address" class="text-box3" maxlength="45" />
			</div>
			<div class="clear"></div>
		</div>
		<div class="clear"></div>
	</div>
	 
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left">
			<span><?php echo language_translate('agent_personal_info_logo');?></span>
		</div>
		<div class="dashboard-info-right">
			<div class="input-box">
				<?php echo form_upload('logo');?>
			</div>
			<div class="clear"></div>
			<?php if($USER->getLogo()){
				echo thumb($USER->getLogoUser(), 70,70);
			}?>
		</div>
		<div class="clear"></div>
	</div>
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left">
			<span><?php echo language_translate('registration_page_country');?></span>
			<!-- <div class="help-text" title="<?php //echo language_translate('registration_page_country_hint');?>"></div> -->
		</div>
		<div class="dashboard-info-right">
			<div class="select-box">
				<?php echo form_dropdown('country_id', getCountryData_ioc($USER->country_id), array($USER->country_id) , 'id="country_id" class="custom"' );?>
			</div>
		 </div>
		<div class="clear"></div>
	</div>
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left">
			<span><?php echo language_translate('registration_page_state');?></span>
			<!-- <div class="help-text" title="<?php //echo language_translate('registration_page_state_hint');?>"></div> -->
		</div>
		<div class="dashboard-info-right">
			<div class="select-box" id="slb_state_id">
				<?php echo form_dropdown('state_id', getStateData_ioc($USER->country_id,$USER->state_id), array($USER->state_id) , 'id="state_id" class="custom"' );?>
			</div>
			<?php echo loader_image_s('id="slb_state_id_loader" class="hidden"');?>
		 </div>
		<div class="clear"></div>
	</div>
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left">
			<span><?php echo language_translate('registration_page_province');?></span>
			<!-- <div class="help-text" title="<?php //echo language_translate('registration_page_province_hint');?>"></div> -->
		</div>
		<div class="dashboard-info-right">
			<div class="select-box" id="slb_province_id" >
				<?php echo form_dropdown('province_id', getProvinceData_ioc($USER->country_id,$USER->state_id,$USER->province_id), array($USER->province_id) , 'id="province_id" class="custom"' );?>
			</div>
			<?php echo loader_image_s('id="slb_province_id_loader" class="hidden"');?>
		 </div>
		<div class="clear"></div>
	</div>
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left">
			<span><?php echo language_translate('registration_page_city');?></span>
			<!-- <div class="help-text" title="<?php //echo language_translate('registration_page_city_hint');?>"></div> -->
		</div>
		<div class="dashboard-info-right">
			<div class="select-box" id="slb_city_id">
				<?php echo form_dropdown('city_id', getCityData_ioc($USER->country_id,$USER->state_id,$USER->province_id,$USER->city_id), array($USER->city_id) , 'id="city_id" class="custom"' );?>
			</div>
			<?php echo loader_image_s('id="slb_city_id_loader" class="hidden"');?>
		 </div>
		<div class="clear"></div>
	</div>
	 
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left">
			<span><?php echo language_translate('borncountry_label');?></span>
		</div>
		<div class="dashboard-info-right">
			<div class="select-box">
				<?php echo form_dropdown('borncountry_id', getBornCountryData_ioc(), array($USER->getBornCountryId()) , 'id="borncountry_id" class="custom"' );?>
			</div>
		 </div>
		<div class="clear"></div>
	</div>	
	
	<div class="dashboard-info-wrapper">
		<div class="dashboard-info-left"> 
			<div class="select-box">
				<input type="submit" class="save-button" value="<?php echo language_translate('appareance_save');?>" /> 
			</div>
		 </div>
		 <div class="dashboard-info-right">
			<?php echo loader_image("id='appareance_loader_image' class='hidden'");?>
		</div>
		<div class="clear"></div>
	</div>	 
	
	<div class="dashboard-info-wrapper">
		<div id="update-message"><?php echo language_translate('update_successfully_message');?></div>
		<div class="clear"></div>
	</div>
	
</form>

<script type="text/javascript">
	$(document).ready(function() { 
		var options = { 
			beforeSubmit:  validateB4Submit,  
			success:       processAfterResponding  
		};	
		$('#submit_personal_info').ajaxForm(options); 
		
		
		$('#country_id').live('change',function(){
			changeCountry_slb($('#country_id').val());
		});
		$('#state_id').live('change',function(){
			changeState_slb($('#state_id').val(),$('#country_id').val());
		});
		$('#province_id').live('change',function(){
			changeProvince_slb($('#state_id').val(),$('#province_id').val(),$('#country_id').val());
		});
	});	
	
	function changeCountry_slb($country_id){
		$('#slb_state_id, #slb_province_id, #slb_city_id').html('<select class="custome"></select>');
		$('select.custome').customStyle();
		$('#slb_state_id_loader, #slb_province_id_loader, #slb_city_id_loader').show();
		$.post(BASE_URI+'registration/changeCountry_async',{country_id:$country_id},function(res){
			$('#slb_state_id_loader').hide();
			$('#slb_state_id').html(res);
			$('select#state_id').customStyle();
			$firtElementValue = $('#state_id').children().first().val();
			changeState_slb($firtElementValue,$country_id);
		});
	}
	
	function changeState_slb($state_id,$country_id){
		$('#slb_province_id, #slb_city_id').html('<select class="custome"></select>');
		$('select.custome').customStyle();
		$('#slb_province_id_loader, #slb_city_id_loader').show();
		$.post(BASE_URI+'registration/changeState_async',{state_id:$state_id,country_id:$country_id},function(res){
			$('#slb_province_id_loader').hide();
			$('#slb_province_id').html(res);
			$('select#province_id').customStyle();
			$firtElementValue = $('#province_id').children().first().val();
			changeProvince_slb($state_id,$firtElementValue,$country_id);
		});
	}
	
	function changeProvince_slb($state_id,$province_id,$country_id){
		$('#slb_city_id').html('<select class="custome"></select>');
		$('select.custome').customStyle();
		$('#slb_city_id_loader').show();
		$.post(BASE_URI+'registration/changeProvince_async',{state_id:$state_id,province_id:$province_id,country_id:$country_id},function(res){
			$('#slb_city_id_loader').hide();
			$('#slb_city_id').html(res);
			$('select#city_id').customStyle();
		});
	}
	
	function validateB4Submit(formData, jqForm, options){
		$('#appareance_loader_image').show();
		return true;
	}
	
	function processAfterResponding(responseText, statusText, xhr, $form) {
		$('#appareance_loader_image').hide();	
		if(responseText == 'ok'){
			updatedShow();
		}else{
			debug(responseText);
		}
	}
</script>